home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / Mesa-3.0 / SRC / MASKING.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-30  |  4.0 KB  |  173 lines

  1. /* $Id: masking.c,v 3.1 1998/02/08 20:19:41 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.0
  6.  * Copyright (C) 1995-1998  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: masking.c,v $
  26.  * Revision 3.1  1998/02/08 20:19:41  brianp
  27.  * ColorMask is now GLubyte[4] instead of GLuint
  28.  *
  29.  * Revision 3.0  1998/01/31 20:58:46  brianp
  30.  * initial rev
  31.  *
  32.  */
  33.  
  34.  
  35. /*
  36.  * Implement the effect of glColorMask and glIndexMask in software.
  37.  */
  38.  
  39.  
  40. #ifdef PC_HEADER
  41. #include "all.h"
  42. #else
  43. #include <string.h>
  44. #include "alphabuf.h"
  45. #include "context.h"
  46. #include "macros.h"
  47. #include "masking.h"
  48. #include "pb.h"
  49. #include "span.h"
  50. #include "types.h"
  51. #endif
  52.  
  53.  
  54.  
  55. void gl_IndexMask( GLcontext *ctx, GLuint mask )
  56. {
  57.    if (INSIDE_BEGIN_END(ctx)) {
  58.       gl_error( ctx, GL_INVALID_OPERATION, "glIndexMask" );
  59.       return;
  60.    }
  61.    ctx->Color.IndexMask = mask;
  62.    ctx->NewState |= NEW_RASTER_OPS;
  63. }
  64.  
  65.  
  66.  
  67. void gl_ColorMask( GLcontext *ctx, GLboolean red, GLboolean green,
  68.                    GLboolean blue, GLboolean alpha )
  69. {
  70.    if (INSIDE_BEGIN_END(ctx)) {
  71.       gl_error( ctx, GL_INVALID_OPERATION, "glColorMask" );
  72.       return;
  73.    }
  74.    ctx->Color.ColorMask[RCOMP] = red    ? 0xff : 0x0;
  75.    ctx->Color.ColorMask[GCOMP] = green  ? 0xff : 0x0;
  76.    ctx->Color.ColorMask[BCOMP] = blue   ? 0xff : 0x0;
  77.    ctx->Color.ColorMask[ACOMP] = alpha  ? 0xff : 0x0;
  78.  
  79.    ctx->NewState |= NEW_RASTER_OPS;
  80. }
  81.  
  82.  
  83.  
  84.  
  85. /*
  86.  * Apply glColorMask to a span of RGBA pixels.
  87.  */
  88. void gl_mask_rgba_span( GLcontext *ctx,
  89.                         GLuint n, GLint x, GLint y, GLubyte rgba[][4] )
  90. {
  91.    GLubyte dest[MAX_WIDTH][4];
  92.    GLuint srcMask = *((GLuint*)ctx->Color.ColorMask);
  93.    GLuint dstMask = ~srcMask;
  94.    GLuint *rgba32 = (GLuint *) rgba;
  95.    GLuint *dest32 = (GLuint *) dest;
  96.    GLuint i;
  97.  
  98.    gl_read_rgba_span( ctx, n, x, y, dest );
  99.  
  100.    for (i=0; i<n; i++) {
  101.       rgba32[i] = (rgba32[i] & srcMask) | (dest32[i] & dstMask);
  102.    }
  103. }
  104.  
  105.  
  106.  
  107. /*
  108.  * Apply glColorMask to an array of RGBA pixels.
  109.  */
  110. void gl_mask_rgba_pixels( GLcontext *ctx,
  111.                           GLuint n, const GLint x[], const GLint y[],
  112.                           GLubyte rgba[][4], const GLubyte mask[] )
  113. {
  114.    GLubyte dest[PB_SIZE][4];
  115.    GLuint srcMask = *((GLuint*)ctx->Color.ColorMask);
  116.    GLuint dstMask = ~srcMask;
  117.    GLuint *rgba32 = (GLuint *) rgba;
  118.    GLuint *dest32 = (GLuint *) dest;
  119.    GLuint i;
  120.  
  121.    (*ctx->Driver.ReadRGBAPixels)( ctx, n, x, y, dest, mask );
  122.  
  123.    for (i=0; i<n; i++) {
  124.       rgba32[i] = (rgba32[i] & srcMask) | (dest32[i] & dstMask);
  125.    }
  126. }
  127.  
  128.  
  129.  
  130. /*
  131.  * Apply glIndexMask to a span of CI pixels.
  132.  */
  133. void gl_mask_index_span( GLcontext *ctx,
  134.                          GLuint n, GLint x, GLint y, GLuint index[] )
  135. {
  136.    GLuint i;
  137.    GLuint fbindexes[MAX_WIDTH];
  138.    GLuint msrc, mdest;
  139.  
  140.    gl_read_index_span( ctx, n, x, y, fbindexes );
  141.  
  142.    msrc = ctx->Color.IndexMask;
  143.    mdest = ~msrc;
  144.  
  145.    for (i=0;i<n;i++) {
  146.       index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
  147.    }
  148. }
  149.  
  150.  
  151.  
  152. /*
  153.  * Apply glIndexMask to an array of CI pixels.
  154.  */
  155. void gl_mask_index_pixels( GLcontext *ctx,
  156.                            GLuint n, const GLint x[], const GLint y[],
  157.                            GLuint index[], const GLubyte mask[] )
  158. {
  159.    GLuint i;
  160.    GLuint fbindexes[PB_SIZE];
  161.    GLuint msrc, mdest;
  162.  
  163.    (*ctx->Driver.ReadCI32Pixels)( ctx, n, x, y, fbindexes, mask );
  164.  
  165.    msrc = ctx->Color.IndexMask;
  166.    mdest = ~msrc;
  167.  
  168.    for (i=0;i<n;i++) {
  169.       index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
  170.    }
  171. }
  172.  
  173.